package com.lv.common.utils

import android.app.Activity
import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.StringRes
import com.blankj.utilcode.util.ToastUtils
import com.lv.common.R
import com.lv.common.base.BaseApplication

/**
 * 作者： ygx
 * 创建日期：2023/5/26 3:19 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * -    _              _           _     _   ____  _             _ _
 * -   / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * -  / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * - / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * -/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 * <p>
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 * 描述：Toast 工具类
 */

fun showToast(msg: String, local: Int = Gravity.CENTER) {
    if (local == Gravity.CENTER) {
        ToastUtils.setGravity(Gravity.CENTER_VERTICAL, 0, 0)
    } else if (local == Gravity.BOTTOM) {
        ToastUtils.setGravity(Gravity.BOTTOM, 0, 0)
    } else if (local == Gravity.TOP) {
        ToastUtils.setGravity(Gravity.TOP, 0, 0)
    }
    val view: View =
        LayoutInflater.from(BaseApplication._context).inflate(R.layout.toast_custom_view, null)
    view.findViewById<TextView>(R.id.id_content).text = msg
    ToastUtils.showCustomShort(view)
}

fun showToast(context: Context, msg: String) {
    val inflater: LayoutInflater = (context as Activity).layoutInflater
    val view: View = inflater.inflate(R.layout.toast_custom_view, null)
    view.findViewById<TextView>(R.id.id_content).text = msg
    ToastUtils.setGravity(Gravity.CENTER_VERTICAL, 0, 0)
    ToastUtils.showCustomShort(view)
}

fun showYgxToast(context: Context, msg: String) {
    val inflater: LayoutInflater = (context as Activity).layoutInflater
    val view: View = inflater.inflate(R.layout.toast_custom_view, null)
    view.findViewById<TextView>(R.id.id_content).text = msg
    val toast = Toast(context)
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0)
    toast.duration = Toast.LENGTH_SHORT
    toast.view = view
    toast.show()
}

fun showToast(@StringRes msg: Int) {
    showToast(msg.toString())
//    ToastUtils.showShort(msg)
}

fun showToast(context: Context, @StringRes msg: Int) {
    val inflater: LayoutInflater = (context as Activity).layoutInflater
    val view: View = inflater.inflate(R.layout.toast_custom_view, null)
    view.findViewById<TextView>(R.id.id_content).text = (context as Activity).getString(msg)
    ToastUtils.setGravity(Gravity.CENTER_VERTICAL, 0, 0)
    ToastUtils.showCustomShort(view)
}

fun showLongToast(msg: String) {
    ToastUtils.showLong(msg)
}

fun showLongToast(@StringRes msg: Int) {
    ToastUtils.showLong(msg)
}